package aad.storyboard.model;


import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.HashMap;

import com.larvalabs.svgandroid.SVG;
import com.larvalabs.svgandroid.SVGParser;


import aad.storyboard.R;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Picture;
import android.graphics.drawable.Drawable;
import android.util.Log;


public class ImageFactory{
        
		private HashMap<String,Image> classMap = new HashMap<String,Image>();
	
		
        private static ImageFactory inst = new ImageFactory();

        private ImageFactory(){}
        
        public static ImageFactory getInstance(){
                return inst;
        }
         
        public void registerClass(String id, Image i){
        	classMap.put(id, i);
        }
        
        public Image createImage(Resources res, int resourceID) throws FileNotFoundException{
                Image img = null;
                String name = res.getString(resourceID);
                String id = name.substring(name.lastIndexOf("."));
                Log.e("ID: ",id);
                	Image product = classMap.get(id);
                	img = product.createImage(res, resourceID);
                	if(img != null){
                        Paint p = new Paint();
                        p.setStyle(Style.FILL);
                img.setName(name);
                img.setPaint(p);
                return img;
        }

                	return product.createImage(res,resourceID);
                
        }

        /*private int determineImageType(String resource) {
                if(resource.endsWith("jpg") || resource.endsWith(".png"))
                        return Image.TYPE_BITMAP;
                else if (resource.endsWith("svg"))
                        return Image.TYPE_VECTOR;
                return -1;
        }*/

}
